Conventional compilers of computer programs use a stack to pass parameters between functions within the computer programs. The stack provides an effective means of managing memory for local variables and communicating parameters among functions. However, the passing of parameters (using the stack) during the execution of computer programs may become time consuming and thereby affect the performance of the application executing such programs. Additionally, in certain applications and/or systems executing such applications, the memory storing the stack and the ability of a processor to manipulate the stack are limited. Moreover, a number of programs are designed to include numerous function calls. For example, a same function may be executed numerous times based on a function call by a different function during execution of a program.
To illustrate, FIG. 1 shows an example of C source code. FIG. 1 illustrates a code segment 100 that includes instructions 102-110. The instruction 102 is the function header. The instruction 104 defines an integer variable “x” and initializes this variable to one. The instruction 106 defines an integer variable “y” and initializes this variable to two. The instruction 108 defines an integer variable “z” and initializes this variable to three. The instruction 110 calls a function B that includes passing the variables “x”, “y” and “z” by reference.
FIG. 2 illustrates a call stack generated by the execution of the C source code example of FIG. 1, according to the prior art. As shown, FIG. 2 illustrates a call stack 200. In a stack entry 202, the variable “x” is pushed on the call stack 200 at address 0x100. The creation of the stack entry 202 corresponds to the execution of the instruction 104. In a stack entry 204, the variable “y” is pushed on the call stack 200 at address 0x0FC. The creation of the stack entry 204 corresponds to the execution of the instruction 106. In a stack entry 206, the variable “z” is pushed on the call stack 200 at address 0x0F8. The creation of the stack entry 206 corresponds to the execution of the instruction 108.
The execution of the function call at the instruction 110 creates stack entries 208-216, which are now described. In the stack entry 208, the variable “z” is pushed on the call stack 200 at address 0x0F4. In the stack entry 210, the variable “y” is pushed on the call stack 200 at address 0x0F0. In the stack entry 212, the variable “x” is pushed on the call stack 200 at address 0x0E0. In the stack entry 214, the program counter is pushed on the call stack 200 to allow for return to the instruction after the completion of the function call to “B” at the instruction 110. In the stack entry 216, the base pointer value for the function “A” is pushed on the call stack 200 at address 0x0E4. This base pointer value for the function “A” is restored after the execution of the function “B” is complete. Stack entry 218 is the location of the stack pointer after the execution of the function “B” is complete (at address 0x0E0).
As shown, when the function “A” calls the function “B”, all three variables x “y” and “z” are copied onto the stack prior to execution of the function “B”. The instructions in function “B” may make reference to the three variables “x”, “y” and “z” during execution. When the function “B” has completed execution, the copies of the variables “x”, “y” and “z” are “popped” off the stack. Thus, copies of the three variables “x”, “y” and “z” were “pushed” onto the stack so that instructions in function “B” could make reference to such variables from a fixed location relative to the base pointer of function “B”. Thus, as described, both call stack resources and processor resources are required to load the variables passed by reference from the calling function to the called function.